﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TCCHWLib.Commands
{
    public class WriteCommand : ICommand
    {
  
        public WriteCommand(object parameter1, ParameterType parametertype1, object parameter2, ParameterType parametertype2,object index,ParameterType Parametertype3)
        {
            m_Operand1 = parameter1;
            m_Operand2 = parameter2;
            m_Operand3 = index;
            m_Type1 = parametertype1;
            m_Type2 = parametertype2;
            m_Type3 = Parametertype3;
            m_ExOperand1 = parameter1;
            m_ExOperand2 = parameter2;
            m_ExOperand3 = index;
            m_ExType1 = parametertype1;
            m_ExType2 = parametertype2;
            m_ExType3 = Parametertype3;
        }

        public override object Execute(Processor processor)
        {
            int address = Convert.ToInt32(m_ExOperand1);
            int index = Convert.ToInt32(m_ExOperand3);
            address += index;
            processor.Cache.Write(address, m_ExOperand2);
            return null;
        }
        public override string ToString()
        {
            return base.ToString() + String.Format("> next pc{0}", NextPC);
        }

        public override void ExecuteGlobal(Processor processor)
        {
            int address = Convert.ToInt32(m_ExOperand1);
            int index = Convert.ToInt32(m_ExOperand3);
            address += index;
            processor.Cache.Write(address, m_ExOperand2);

        }
    }
}
